<?php
/**
 * 爬虫小工具
 * @since 1.0 <2015-9-29> SoChishun <14507247@qq.com> Added.
 */
if(I('url')){
    get_html();
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>爬虫小工具</title>
    </head>
    <body>
        <fieldset>
            <legend>规则设定</legend>
        <form method="post">
            <table>
                <tr><th>网址</th><td><input type="text" name="url" value="http://dn101.cn/news.aspx?page=2" required="required" /></td></tr>
                <tr><th>分页参数</th><td><input type="text" name="page_name" value="page" /></td></tr>
            </table>
            <button type="submit">开始抓取</button><button type="reset">重置</button>
        </form>
        </fieldset>
    </body>
</html>
<?php

/**
 * 获取用户变量
 * @param type $name
 * @param type $defv
 * @return type
 * @since 1.0 <2015-9-29> SoChishun Added.
 */
function I($name,$defv=''){
    if(isset($_GET[$name])){
        return $_GET[$name];
    }
    if(isset($_POST[$name])){
        return $_POST[$name];
    }
    return $defv;
}
function get_html(){
    $data=$_POST;
    include 'Snoopy.class.php';
    $snoopy=new Snoopy();
    $results=$snoopy->fetch($data['url']);
    preg_match_all('/<div class="float_l hidden_more" style="width:500px;">([.]?)<\/div>/', $results->results, $matches);
    var_export($matches);
}
?>
